package com.lili.operate.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.operate.Distribution;
import com.lili.operate.mapper.DistributionMapper;
import com.lili.operate.service.DistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class DistributionServiceImpl implements DistributionService {

    @Autowired
    DistributionMapper distributionMapper;


    @Override
    public Page<Distribution> queryDistribution(Map map) {
        int current = 1;
        int size = 3;
        if(map.get("current") != null)
            current = Integer.parseInt(map.get("current").toString());
        if (map.get("size") != null)
            size = Integer.parseInt(map.get("size").toString());
        Page<Distribution> page = new Page<>(current,size);
        QueryWrapper<Distribution> wrapper = new QueryWrapper<>();
        if (map.get("distributionStatus") != null)
            wrapper.eq("distribution_status",map.get("distributionStatus").toString());
        if (map.get("memberName") != null)
            wrapper.eq("member_name",map.get("memberName").toString());
        distributionMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public int updateStatus(long id, String status) {
        return distributionMapper.updateStatus(id,status);
    }
}
